#include "vtor_buffer.h"

// 模块宏
#ifdef __VTOR_BUFFER__

// 工程宏
//#define __USER_PROJECT_DEMO__
#ifdef __USER_PROJECT_DEMO__

#include "vtor_elec_module.h"



uint8_t VtorMultiBuffer_Memory[32 * 8] = {0};
uint8_t VtorSingleBuffer_Memory[64] = {0};

VtorMultiBuffer trigUartMultiBuf = {0};

VtorSingleBuffer terminalUartSingleBuf = {0};



void VtorSingleBuffer_OverflowCallback(VtorSingleBuffer* buf)
{

}


void VtorMultiBuffer_OverflowCallback(VtorMultiBuffer* buf)
{

}



void VtorMultiBuffer_SwitchInBufCallback(VtorMultiBuffer* buf)
{
	// 释放信号量，设置标志位等
	//VtorTimer_Create(VtorTimer_ExTrigBlrUartMultiBufferTask, 0);
}

void VtorMultiBuffer_SwitchOutBufCallback(VtorMultiBuffer* buf)
{
	// 清空信号量，清空标志位
	//VtorTimer_Delete(VtorTimer_ExTrigBlrUartMultiBufferTask);
}




// 自行编写判断是否完成一帧数据
uint8_t VtorMultiBuffer_CheckSwitchInBuf(VtorMultiBuffer* buf)
{
	uint8_t switchFlag = 0;
	// 换行回调 // 将溢回调，整帧回调
	if(buf->inBuf[buf->inBufLen - 2] == '\r'
		&& buf->inBuf[buf->inBufLen - 1] == '\n')
	{
		// 满足切换buf，设置标志位
		switchFlag = 1;
	}
	// 将溢回调
	else if(buf->inBufLen + 3 > buf->maxBufLen)
	{
		switchFlag = 1;
	}
	return switchFlag;
}


void VtorBuffer_Init()
{
	VtorMultiBuffer* buf = &trigUartMultiBuf;
	buf->bufArray = VtorMultiBuffer_Memory; // 直接指向一片内存
	buf->maxBufLen = 32;
	buf->bufCnt = 8;
	buf->inBuf = buf->bufArray;
	buf->outBuf = buf->inBuf;
	
	
	VtorSingleBuffer* singleBuf = &terminalUartSingleBuf;
	singleBuf->buf = VtorSingleBuffer_Memory;
	singleBuf->maxLen = 20;
	
}


#endif // __USER_PROJECT_DEMO__

#endif // __VTOR_BUFFER__


